package com.xinzhidi.util;


import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;

public class SendMessageTemplate {

    /**
     * 发送短信
     * @param signName 签名
     * @param templateCode 模板
     * @param phoneNumbers 手机号
     * @param param 参数
     */
    public static SendSmsResponse sendMessage(String signName, String templateCode, String phoneNumbers, String param, String type){
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", " ", " ");
        IAcsClient client = new DefaultAcsClient(profile);
        SendSmsRequest request = new SendSmsRequest();
        request.setRegionId("cn-hangzhou");
        request.setPhoneNumbers(phoneNumbers);
        request.setSignName(signName);
        request.setTemplateCode(templateCode);
        request.setTemplateParam("{\""+type+"\":\""+param+"\"}");
        SendSmsResponse response = null;
        try {
            response = client.getAcsResponse(request);
            System.out.println(response.getMessage());
            System.out.println("短信发送成功");
            if (response.getMessage().equals("OK")){
                response.setCode("0");
            }
        }catch (ClientException e) {
            e.printStackTrace();
        }
        return response;
    }


}

